import Vue from 'vue';
import Router from 'vue-router';

import Home from "../views/Home";
import Main from "../views/Main";
import AboutUs from "../views/AboutUs";
import NewsCenter from "../views/NewsCenter";
import Productcenter from "../views/Productcenter";
import Engineering from "../views/Engineering";
import ContactUs from "../views/ContactUs";
import Partners from "../views/Partners";
import UploadFile from "../views/UploadFile";
import Markdown from "../components/Markdown";


Vue.use(Router);

//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = Router.prototype.push;
const originalReplace = Router.prototype.replace;
//push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};
//replace
Router.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject);
  return originalReplace.call(this, location).catch(err => err);
};

//1.创建路由组件
//2.将路由与租组件映射
//3.创建router实力
const routes=[
  {
    path:"/",
    component:Main,
    name: "Main",
    redirect: "/home",  //重定向
    children:[
      {
        path:"/home",
        component:Home,
        name: "Home"
      },{
        path:"/aboutUs",
        component:AboutUs,
        name: "AboutUs"
      },{
        path:"/newsCenter",
        component:NewsCenter,
        name: "NewsCenter"
      },{
        path:"/productcenter",
        component:Productcenter,
        name: "Productcenter"
      },{
        path:"/engineering",
        component:Engineering,
        name: "Engineering"
      },{
        path:"/contactUs",
        component:ContactUs,
        name: "ContactUs"
      },{
        path:"/partners",
        component:Partners,
        name: "Partners"
      },{
        path:"/uploadFile",
        component:UploadFile,
        name: "UploadFile"
      },{
        path:"/markdown",
        component:Markdown,
        name: "Markdown"
      }
    ]
  }
];
const router=new Router({
  //mode:'history',
  routes  //缩写 相当于routes:routes
});

export default router;















